﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace AltimilliaLibrary
{
  public class Terrain
  {
    public List<TileRow> TileRowList {get;set;}
    public Texture2D Texture { get; set; }
    private int columns;
    private int rows;
    private Rectangle dimensions;
    private Rectangle[,] rectangles;
    public int tilewidth;
    public int tileheight;

    public Terrain(List<TileRow> list, Texture2D Texture, int columns, int rows,int tileWidth, int tileHeight, Rectangle Dimensions)
    {
      this.TileRowList = list;
      this.Texture = Texture;
      this.columns = columns;
      this.rows = rows;
      this.dimensions = Dimensions;
      this.tileheight = tileHeight;
      this.tilewidth = tileWidth;
    }

    private void ProcessTileSet()
    {
      for (int i = 0; i < rows; i++)
      {
        for (int j = 0; j < columns; j++)
        {
          rectangles[i, j] = new Rectangle(j * tilewidth, i * tileheight, tilewidth, tileheight);
        }
      }
    }

    public Rectangle Rectangle(int position)
    {
      return rectangles[((position - 1)/columns),((position - 1) % columns)];
    }

    public TileRow this[int index]
    {
      get
      {
        return TileRowList[index];
      }
    }
  }
}
